<?php
namespace Kxdrmobile\Model;
use Think\Model;
class UserGiftsModel extends Model{
	public $sid;
	public $uid;
	public $gift_id;
	public $limit;
	public $all_count;
	public $gropu_count;
	public function loadMyGifts(){
		$where["sid"]=$this->sid;
		$where["user_id"]=$this->uid;
		$gifts = $this->where($where)->group("`gift_id`")->limit($this->limit)->getField("`gift_id`,COUNT(`id`) AS count,`gift_name`, `gift_pic_url`,`gift_type`");
		$GFT_TYPE = C("GFT_TYPE");
		foreach($gifts as $k=>$gift){
			foreach($GFT_TYPE as $tp){
				if($gift["gift_type"] == $tp["id"]){
					$gifts[$k]["gift_type_name"] = $tp["name"];
				}
			}
		}
		return $gifts;
	}
	public function showMyGifts(){
		$where["sid"]=$this->sid;
		$where["user_id"]=$this->uid;
		$where["gift_id"]=$this->gift_id;
		$gifts = $this->where($where)->limit($this->limit)->getField("`id`,`gift_name`, `gift_pic_url`,`gift_type`");
		$GFT_TYPE = C("GFT_TYPE");
		foreach($gifts as $k=>$gift){
			foreach($GFT_TYPE as $tp){
				if($gift["gift_type"] == $tp["id"]){
					$gifts[$k]["gift_type"] = $tp["name"];
				}
			}
		}
		return $gifts;
	}
	public function getAllCount(){
		$where["sid"]=$this->sid;
		$where["user_id"]=$this->uid;
		$this->all_count = $this->where($where)->getField("COUNT(`id`) as count");
		return $this->all_count ;
	}
	public function getGroupCount(){
		$where["sid"]=$this->sid;
		$where["user_id"]=$this->uid;
		$this->gropu_count = $this->where($where)->getField("COUNT(distinct `gift_id`) AS count");
		return $this->gropu_count ;
	}
}